<template>
	<view class="container">
		<view class="queueBox">
			<view class="queueBox_top">

				<view class="shade shade1"></view>
				<view class="shade shade2"></view>

				<view class="queueBox_top_text">

					<h1>{{queueList.num}}</h1>
					<text v-if="queueList.status == 1">排队中</text>
					<text v-else-if="queueList.status == 2">轮到你啦！快进馆吧！</text>
					<text v-else-if="queueList.status == 3">已进入</text>
					<text v-else-if="queueList.status == 4">长时间未到时间已过</text>
					<text v-else>咨询门店排队方式</text>
				</view>

				<view class="spot"></view>

				<view class="queueBox_bottom_text">
					<view class="queueBox_bottom_text_top">
						<text>您前面还有<text class="red">{{queueList.currentCount}}</text>人</text>
						<view v-if="queueList.status == 4" class="refresh" @click="refresh1()">
							<icon class="iconfont iconhuanyipi"></icon>重新刷新
						</view>
						<view v-else class="refresh" @click="refresh()">
							<icon class="iconfont iconhuanyipi"></icon>刷新
						</view>
					</view>
					<view class="queueBox_bottom_text_bottom">
						注：到您的号码时请立刻进馆，过号请重新取号
					</view>
				</view>
			</view>
			<view class="queueBox_center">
				<view class="queueBox_center_left">
					<image src="http://qichong-1256206693-1256206693.cos.ap-nanjing.myqcloud.com/upload/20210630/7532e54b8fd4b9a00ac28a194428f635.png" mode="widthFix"></image>
					<view class="queueBox_center_left_text">
						<h1>奇宠日记</h1>
						<text>关注公众号，可同步排队信息，查看更多消息</text>
					</view>
				</view>
				<view class="queueBox_center_right" @tap="copy('奇宠日记','公众号名称已复制')">
					马上关注
				</view>
				<official-account></official-account>
			</view>
			<view class="queueBox_bottom">
				<view class="queueBox_bottom_top">
					温馨提示：
				</view>
				<view class="queueBox_bottom_bottom">
					{{queueList.remarks}}
				</view>
			</view>
		</view>
		<!-- 到你了 -->
		<view class="k">
			<van-popup :show="entranceShow">
				<view class="entranceBox">
					<image src="/static/images/mine/yepaidui.png" mode="widthFix"></image>
					<view class="entranceBox_text">
						轮到你啦！快进馆吧！
					</view>
					<view class="entranceBox_bottom" @click="this.entranceShow = false">
						知道了
					</view>
				</view>
			</van-popup>
		</view>
		<!-- 没有排队扫码 -->
		<view class="noneBox" v-if="noneQueueShow">
			<image src="http://qichong-1256206693-1256206693.cos.ap-nanjing.myqcloud.com/upload/20210617/2ebf57e8968f91945a73f56a725f8fb3.png" mode="widthFix"></image>
			<text>你还没有扫码排队...</text>
		</view>
	</view>
</template>

<script>
	const thorui = require('@/components/common/tui-clipboard/tui-clipboard.js');
	import {
		getEstablish,
		refreshEstablish,
		anewEstablish
	} from '@/api/queue.js'

	import {
		mapGetters
	} from 'vuex'

	export default {
		data() {
			return {
				queueList: [],
				// 到你了
				entranceShow: false,
				// 没有排队
				noneQueueShow: false,
				// 门店id
				// shopId:''
				currentId: ''
			};
		},
		computed: {
			...mapGetters('m_user', ['currentStoreId', 'isLogin'])
		},
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV == true) {
						this.refresh();
					}
				},
				deep: true
			}
		},

		onLoad(option) {
			if (option.shopId) {
				this.currentId = option.shopId
			} else {
				this.currentId = this.currentStoreId
			}

			this.$eventHub.$on('emit', (data) => {
				this.currentId = data.id;
				this.refresh();
			});
			this.refresh();
			this.StateSetInterval()
		},
		//发送给朋友
		onShareAppMessage: function() {
			return {
				title: "奇宠日记",
				path: '/pages/tabbar/index/index',
				imageUrl: "http://dev-1256206693.cos.ap-beijing.myqcloud.com/upload/20210105/1baeee01a05a273297c65145c2b6398b.jpg"
			};
		},
		//分享到朋友圈
		onShareTimeline: function() {
			return {
				title: "奇宠日记",
        path: '/pages/tabbar/index/index',
				imageUrl: "http://dev-1256206693.cos.ap-beijing.myqcloud.com/upload/20210105/1baeee01a05a273297c65145c2b6398b.jpg"
			};
		},
		methods: {
			copy: function(text, msg) {
				const that = this
				thorui.getClipboardData(text, (res) => {
					// #ifdef H5 || MP-ALIPAY
					if (res) {
						that.$util.Tips({
							title: msg
						});
					} else {
						that.$util.Tips({
							title: "内容复制失败"
						});
					}
					// #endif
				})
			},
			// 刷新
			refresh() {
				if (this.currentId == 0 || this.currentId == '') {
					return this.$util.Tips({
						title: "请先定位到门店"
					}, {
						tab: 2,
						url: '/pages/shop/list'
					});
				}
				getEstablish(this.currentId).then(res => {
					this.queueList = res.data
					if (this.queueList.status == 2) {
						this.entranceShow = true
					}
				})
			},
			// 重新刷新
			refresh1() {
				anewEstablish(this.currentId).then(res => {
					this.queueList = res.data
					if (this.queueList.status == 2) {
						this.entranceShow = true
					}
					this.$util.Tips({
						title: '刷新成功~',
					})
				}).catch(res => {
					this.$util.Tips({
						title: '刷新失败~',
					})
				})
			},

			// 定时器
			StateSetInterval() {

			}
		}
	}
</script>

<style lang="scss">
	.k {
		/deep/.van-popup {
			width: 504rpx;
			height: 466rpx;
			border-radius: 30rpx;
			padding: 58rpx 96rpx;
			background-color: rgba(255, 255, 255, 1);

			.entranceBox {
				display: flex;
				flex-direction: column;
				align-items: center;

				image {
					width: 160rpx;
					height: 173rpx;
					margin-left: 20rpx;
				}

				.entranceBox_text {
					margin-top: 16rpx;
					margin-bottom: 40rpx;
					margin-left: 20rpx;
					font-size: 30rpx;
					color: rgba(61, 61, 61, .5);
				}

				.entranceBox_bottom {
					width: 311rpx;
					height: 74rpx;
					border-radius: 37rpx;
					background-color: rgba(253, 211, 56, 1);
					font-size: 26rpx;
					text-align: center;
					line-height: 74rpx;
					color: rgba(61, 61, 61, 1);
				}
			}
		}
	}

	.queueBox {
		padding: 40rpx 24rpx;
		background-color: rgba(255, 255, 255, 1);
	}

	.queueBox_top {
		position: relative;
		width: 702rpx;
		height: 650rpx;
		border-radius: 20rpx;
		background-color: rgba(255, 255, 255, 1);
		box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.04);

		.queueBox_top_text {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-top: 80rpx;

			h1 {
				font-size: 100rpx;
				font-weight: 600;
			}

			text {
				font-size: 30rpx;
				color: rgba(61, 61, 61, .5);
			}
		}

		.queueBox_bottom_text {
			width: 550rpx;
			position: absolute;
			bottom: 50rpx;
			left: 50%;
			transform: translate(-50%);

			.queueBox_bottom_text_top {
				margin-bottom: 80rpx;
				display: flex;
				justify-content: space-between;
				align-items: flex-end;

				text {
					font-size: 30rpx;
					color: rgba(61, 61, 61, .5);
				}

				.red {
					padding: 0 15rpx;
					font-size: 60rpx;
					color: rgba(255, 87, 51, 1);
				}

				.refresh {
					position: relative;
					color: rgba(61, 61, 61, 1);

				}
			}

			.queueBox_bottom_text_bottom {
				text-align: center;
				font-size: 24rpx;
				color: rgba(61, 61, 61, .5);
			}
		}

		.spot {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			width: 100%;
			height: 1rpx;
			border-bottom: 1rpx dashed rgba(224, 224, 224, 1);
		}

		.shade {
			width: 100rpx;
			height: 100rpx;
			background-color: rgba(255, 255, 255, 1);
			border-radius: 50%;
			box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.02) inset;
			z-index: 1;
		}

		.shade1 {
			position: absolute;
			top: 50%;
			left: -46rpx;
			transform: translateY(-50%);
		}

		.shade2 {
			position: absolute;
			top: 50%;
			left: 650rpx;
			transform: translateY(-50%);
		}
	}

	.queueBox_center {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 702rpx;
		height: 205rpx;
		border-radius: 20rpx;
		padding: 0 24rpx;
		margin: 30rpx 0;
		box-sizing: border-box;
		background-color: rgba(255, 255, 255, 1);
		box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.04);

		.queueBox_center_left {
			display: flex;

			image {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
			}

			.queueBox_center_left_text {
				width: 330rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				margin-left: 20rpx;

				h1 {
					font-size: 32rpx;
					font-weight: 600;
					color: rgba(61, 61, 61, 1);
					margin-bottom: 12rpx;
				}

				text {
					font-size: 24rpx;
					color: rgba(61, 61, 61, .5);
				}
			}
		}

		.queueBox_center_right {
			width: 153rpx;
			height: 54rpx;
			border-radius: 211px;
			background-color: rgba(253, 211, 56, 1);
			color: rgba(61, 61, 61, 1);
			font-size: 26rpx;
			text-align: center;
			line-height: 54rpx;
			font-weight: 600;
		}
	}

	.queueBox_bottom {
		display: flex;
		flex-direction: column;
		justify-content: center;
		width: 702rpx;
		height: 205rpx;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 0 24rpx;
		background-color: rgba(255, 255, 255, 1);
		box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.04);

		.queueBox_bottom_top {
			font-size: 24rpx;
			color: rgba(255, 87, 51, 1);
			margin-bottom: 15rpx;
		}

		.queueBox_bottom_bottom {
			font-size: 24rpx;
			line-height: 1.5;
			color: rgba(61, 61, 61, 0.5);
		}
	}

	.noneBox {
		display: flex;
		flex-direction: column;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);

		image {
			width: 184rpx;
			height: 321rpx;
			margin-left: 10rpx;
		}

		text {
			margin-top: 24rpx;
			font-size: 30rpx;
			color: rgba(61, 61, 61, .5);
		}
	}
</style>
